﻿namespace Api.Shared.Model.Impl
{
    public class PersonsList
    {
        public PersonsList(int size)
        {
            for (int i = 0; i < size; i++)
            {
                Persons.Add(new() { Age = i + 1, Name = $"DDD{i}" });
            }
        }

        public List<Person> Persons { get; set; } = new();

        public Person this[int index]
        {
            get
            {
                if (index < 0 || index > Persons.Count)
                {
                    throw new IndexOutOfRangeException("Index was out of range.");
                }

                return Persons[index];
            }
            set
            {
                if (index < 0 || index > Persons.Count)
                {
                    throw new IndexOutOfRangeException("Index was out of range.");
                }

                Persons[index] = value;
            }
        }
    }
}
